/**
 * 描述: 日志查询
 * 日期：2019-07-24
 */
function changeDateFormat1(cellval) {
  var val=cellval+"";

  if( val != '' && val !=null && val !='null' &&  val!='undefined')
  {
    return val.substring(0,10)
  }

}

(function(E, KIT, RES) {
  var URL_ROOT = RES.URL_ROOT + "/log",
    URL_FIND = URL_ROOT + "/getObjects";

  function _initSearchDataview(page) {
    rapid("#frmSearch").dataview({
      colSize: 0,
      padding: false,
      fields: [{
        editor: {
          name: "operateTimeBegin", type: "datetimepicker", tip: "操作日期 - 起",
          mode: "yMd", textFormat: "yyyy年MM月dd日", onchange: function(e, valid) {
            var __value = this.val(),
              __end = e.ui("operateTimeEnd");

            if(rapid.hasValue(__value)) {
              __end.min(__value).disabled(false);
            } else {
              __end.disabled(true);
            }

            __end.val(null);
          }
        }
      }, {
        editor: {
          name: "operateTimeEnd", type: "datetimepicker", tip: "操作日期 - 止",
          mode: "yMd", textFormat: "yyyy年MM月dd日", disabled: true
        }
      }, {
        editor: {
          name: "model", tip: "模块"
        }
      }, {
        editor: {
          name: "operate", tip: "操作"
        }
      }, {
        editor: {
          name: "operatorLoginId", tip: "用户账号"
        }
      }, {
        editor: {
          name: "operatorName", tip: "用户名称"
        }
      }, {
        editor: {
          name: "content", tip: "操作描述"
        }
      }, {
        template: function() {
          return E.view({cssClass: "r-nowrap"},
            E.button({
              id: "btnSearch", icon: "fa-search", cssClass: "r-m-r", text: "搜索"
            }),
            E.button({
              id: "btnReset", icon: "fa-undo", text: "重置"
            })
          );
        }
      }],
      oninit: function() {
        rapid.ui("#btnSearch").on("click", function() {
          rapid("#grdLog").grid().load({
            data: rapid("#frmSearch").dataview().serializeJson()
          });
        });

        rapid.ui("#btnReset").on("click", function() {
          rapid("#frmSearch").dataview().reset();
        });
      }
    });
  }

  function _initGrid(page) {
    rapid("#grdLog").grid({
      height: function() {
        return rapid(page.main()).height();
      },
      dataSource: {
        url: URL_FIND
      },
      pageable: true,
      keyFields: "log_id",
      colWidth: "fill",
      rowHeight: "always",
      fields: [{
        title: "业务模块", name: "model", width: 80
      }, {
        title: "操作", name: "operate", width: 70
      }, {
        title: "用户帐号", name: "operator_login_id", width: 100
      }, {
        title: "用户名称", name: "operator_name", width: 80
      }, {
        title: "操作时间", name: "operate_time", width: 90,formatter: function (value, row, index) {
          return changeDateFormat1(value)}
      }, {
        title: "IP", name: "ip", width: 100
      }, {
        title: "操作描述", name: "content"
      }]
    });
  }

  rapid.Page.create({
    render: {
      titleBar: "日志查询",
      header: E.form({id: "frmSearch"}),
      main: E.grid({id: "grdLog"})
    }
  })(function() {
    _initSearchDataview(this);

    _initGrid(this);

  }).init();
  
})(rapid.html.Element, rapid.kit, rapid.res);